package com.web.dao;

import com.web.entity.Bank;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * @author FDjavaone
 */
public interface BankMapper {


    @Delete({
            "delete from t_bank",
            " where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
            "insert into t_bank (m_id, name, ",
            " card_no, phone, bank_name, ",
            " card_type, default_status, ",
            " create_time, modify_time)",
            " values (#{mId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, ",
            " #{cardNo,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, #{bankName,jdbcType=VARCHAR}, ",
            " #{cardType,jdbcType=VARCHAR}, #{defaultStatus,jdbcType=INTEGER}, ",
            " #{createTime,jdbcType=TIMESTAMP}, #{modifyTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
    int insert(Bank record);

    @InsertProvider(type = BankSqlProvider.class, method = "insertSelective")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
    int insertSelective(Bank record);


    @Select({
            "select",
            " id, m_id, name, card_no, phone, bank_name, card_type, default_status, create_time, ",
            " modify_time",
            " from t_bank",
            " where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "m_id", property = "mId", jdbcType = JdbcType.BIGINT),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "card_no", property = "cardNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR),
            @Result(column = "bank_name", property = "bankName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "card_type", property = "cardType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "default_status", property = "defaultStatus", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP)
    })
    Bank selectByPrimaryKey(Long id);

    @UpdateProvider(type = BankSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Bank record);

    @Update({
            "update t_bank",
            " set m_id = #{mId,jdbcType=BIGINT},",
            " name = #{name,jdbcType=VARCHAR},",
            " card_no = #{cardNo,jdbcType=VARCHAR},",
            " phone = #{phone,jdbcType=VARCHAR},",
            " bank_name = #{bankName,jdbcType=VARCHAR},",
            " card_type = #{cardType,jdbcType=VARCHAR},",
            " default_status = #{defaultStatus,jdbcType=INTEGER},",
            " create_time = #{createTime,jdbcType=TIMESTAMP},",
            " modify_time = #{modifyTime,jdbcType=TIMESTAMP}",
            " where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Bank record);

    @Select({
            "select",
            " id, m_id, name, card_no, phone, bank_name, card_type, default_status, create_time, ",
            " modify_time",
            " from t_bank",
            " where m_id = #{aLong,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "m_id", property = "mId", jdbcType = JdbcType.BIGINT),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "card_no", property = "cardNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR),
            @Result(column = "bank_name", property = "bankName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "card_type", property = "cardType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "default_status", property = "defaultStatus", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP)
    })
    List<Bank> selectByMid(Long aLong);

    @Update({
            "update t_bank",
            " set default_status = #{defaultStatus,jdbcType=INTEGER},",
            " modify_time = #{modifyTime,jdbcType=TIMESTAMP}",
            " where m_id = #{mId,jdbcType=BIGINT}"
    })
    int setAllAddressNotDefault(Bank bank);
}